package com.wssnail.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Author: yan
 * @CreateTime: 2022-09-28 10:44
 * @Description: 调用微信接口的工具类
 * @Version: 1.0
 */
@Component
@Slf4j
public class WxUtils {

    @Value("${wssnail.wx.token_url}")
    private String tokenUrl;

    public String getToken(){
        String result = HttpUtil.get(tokenUrl);
        log.info(">>>>>>>>>>>>>>>>>返回结果："+result);
        JSONObject jsonObject = JSONObject.parseObject(result);
        String access_token = jsonObject.getString("access_token");
        if (StringUtils.isNotBlank(access_token)){
            //放入redis,然后返回
            return access_token;
        }
        return null;
    }
}
